// pages/myAppointment/myAppointment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    allRecord: 0,
    awaitRecord: 0,
    invalidRecord: 0,
    username:'',
    userwxid:'',
    array:[],
    appointRecord:[],
    waitAppointRecord:[], //待签到记录
    isUsedAppointRecord:[], //已使用记录
  },
  getAppointRecord(){
    wx.request({
      url: `http://8.219.238.141/appointment/selectByWxid?wxid=${this.data.userwxid}`,
      method:'GET',
      success: (res) => {
        this.setData({
          appointRecord: [...this.data.appointRecord, ...res.data.data]
        });
    }
  });
  //重新更新页面
  this.setData({
    appointRecord: this.data.appointRecord
  });
  },
  getWaitAppointRecord(){
    wx.request({
      url: `http://8.219.238.141/appointment/selectByWxidAndNotUsed?wxid=${this.data.userwxid}&isused=false`,
      method:'GET',
      success: (res) => {
        this.setData({
          waitAppointRecord: [...this.data.waitAppointRecord, ...res.data.data]
        });
    }
  });
  this.setData({
    waitAppointRecord: this.data.waitAppointRecord
  });
  
  },
  getIsUsedAppointRecord(){
    
    wx.request({
      url: `http://8.219.238.141/appointment/selectByWxidAndUsed?wxid=${this.data.userwxid}&isused=true`,
      method:'GET',
      success: (res) => {
        this.setData({
          isUsedAppointRecord: [...this.data.isUsedAppointRecord, ...res.data.data]
        });
    }
  });
  this.setData({
    isUsedAppointRecord: this.data.isUsedAppointRecord
  });
  },
  onChange(event) {
    wx.showToast({
      title: `切换到 ${event.detail.name}`,
      icon: 'none',
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getAppointRecord();
    this.getIsUsedAppointRecord();
    this.getWaitAppointRecord();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var app = getApp();
    this.setData({
      username: app.globalData.userName,
      userwxid: app.globalData.userWxid,
    });
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})